/**
 *  用户接口
 */

import request from '@/utils/request.js';
import { HTTP_REQUEST_URL } from '@/config/index.js';

const api = {}

// 登录
api.login = data => request.globalRequest({
	methods: 'POST',
	url: HTTP_REQUEST_URL + '/client/user/login',
	data: data,
})

// 退出登录
api.logout = data => request.globalRequest({
	methods: 'POST',
	url: HTTP_REQUEST_URL + '/client/user/logout',
	data: data,
})

// 获取用户信息
api.getUserProfile = data => request.globalRequest({
	methods: 'POST',
	url: HTTP_REQUEST_URL + '/client/user/profile',
	data: data,
})

// 设置用户昵称
api.setNickname = data => request.globalRequest({
	methods: 'POST',
	url: HTTP_REQUEST_URL + '/client/user/setNickname',
	data: data,
})

// 设置用户头像
api.setAvatar = id => request.globalRequest({
	methods: 'POST',
	url: HTTP_REQUEST_URL + '/client/user/setAvatar',
	data: {
		fid: id
	}
})

// 上传用户头像
api.uploadAvatar = data => request.uploadFile({
	url: HTTP_REQUEST_URL + '/files/upload',
	filePath: data.filePath,
	name: 'file',
	data: {
		accept: 'image',
		dir: 'avatar',
		category_id: '2',
		type: 1,
	},
})

// 设置邀请码
api.setInvitationCode = data => request.globalRequest({
	url: HTTP_REQUEST_URL + '/client/user/setInvitationCode',
	data: data,
})

// 上传图片
api.upload = data => request.uploadFile({
	url: HTTP_REQUEST_URL + '/files/upload',
	filePath: data.filePath,
	name: data.name,
	data: data.data,
})

// 获取标签列表
api.getTags = data => request.globalRequest({
	methods: 'POST',
	url: HTTP_REQUEST_URL + '/tag/index',
	data: data,
})

// 获取区域列表
api.getArea = data => request.globalRequest({
	methods: 'POST',
	url: HTTP_REQUEST_URL + '/area/index',
	data: data,
})

// 经纬度转换地址
api.getLngLatAddress = data => request.globalRequest({
	methods: 'POST',
	url: HTTP_REQUEST_URL + '/map/getAddressByLonglat',
	data: data,
})

export default api